Previous Book Contents Book Index Next

Inside Macintosh: Programming With JManager /
Chapter 1 - Using JManager / Creating a Java Runtime Environment


Servicing Other Threads

When you are running a Macintosh embedding application, you must explicitly tell JManager to give up time to the Java virtual machine. You do so by using the JMIdle function (page 57) in your main event loop. Listing 1-2 shows an example of using JMIdle.

Listing 1-2 Using the JMIdle function

Boolean MainEventLoopContinues = true; 

while (MainEventLoopContinues) {
   EventRecord eve;
   
   if (! WaitNextEvent(everyEvent, &eve, 30, nil) || 
      eve.what == nullEvent)
         JMIdle(theSession, 100);
      else
         handleEvent(&eve);
   }
The value specified in JMIdle indicates how many milliseconds to allot to other threads. JMIdle returns immediately if no threads need servicing. JMIdle also returns if a user event occurs in the current session.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
23 APR 1997